package com.iwhalecloud.bss.kite.cucc.web.config;

import com.iwhalecloud.bss.kite.cucc.web.filter.CrossDomainCORSFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.DispatcherType;
import java.util.ArrayList;
import java.util.List;

/**
 * 跨域访问过滤器配置
 */
@Configuration
public class CrossDomainCORSFilterConfig {

    @Bean
    public FilterRegistrationBean crosFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setDispatcherTypes(DispatcherType.REQUEST);
        registration.setEnabled(true);
        registration.setFilter(new CrossDomainCORSFilter());
        registration.setName(CrossDomainCORSFilter.class.getSimpleName());

        // 拦截以下URL
        List<String> urlPatterns = new ArrayList<>();
        urlPatterns.add("/*");
        registration.setUrlPatterns(urlPatterns);

        return registration;
    }
}
